<?php
class CONNECT{
	protected $connection;
	private $server,$user,$password,$database;
	
	public function connectOpen(){
		$args = func_get_args();
		$numargs = func_num_args();
		if($numargs != 0 && $numargs != 4){
			echo "Insufficient Arguments";
			exit;
		}else{
			switch ($numargs){
				case 0:
					self::__construct1();  
					break;
				case 4:
					self::__construct2($args);
					break;
			}
			self::connectDatabse();
		}
	}
	
	private function __construct1(){
		
		$this->server = '192.168.0.73';
		$this->user = 'root';
		$this->password = 'binary';
		$this->database = 'kbazaar';
	}
	
	private function __construct2($args){
		
		$this->server = $args[0];
		$this->user = $args[1];
		$this->password = $args[2];
		$this->database = $args[3];
	}
	
	public function connectDatabse(){
		
		$this->connection = mysql_connect($this->server,$this->user,$this->password);
		if($this->connection === false){
			echo "Could not connect server ".mysql_error($con);
			exit;
		}
//		else{
//			echo "<br>Connected Successfully";
//		}

		if(!mysql_select_db($this->database,$this->connection)){
			echo "Could not select database ".mysql_error($this->connection);
			exit;
		}
//		else{
//			echo "<br>".$this->database.": Database Connected Successfully";
//		}
	}
	
	public function connectionClose(){
		if($this->connectionStatus()){
			mysql_close($this->connection);
			$this->connection = null;		
		}
	}
	
	public function connectionStatus(){
		if(@mysql_ping($this->connection) === true)
			return true;
		else
			return false;
	}
	
	public function getDatabaseName(){
		return $this->database;
	}
	
	public function getServer(){
		return $this->server;
	}
	
	public function getUser(){
		return $this->user;
	}
	
	public function getServerConfig(){
		$server['server'] = $this->server;
		$server['user'] = $this->user;
		$server['database'] = $this->database;
		return $server;
	}
}